import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
// import viteESLintPlugin from 'vite-plugin-eslint'
import { vitePluginForArco } from '@arco-plugins/vite-react'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'    // 封装svg图标
import setting from './src/settings.json';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const config = loadEnv(mode, './')
  return {
    plugins: [
      react(),
      vitePluginForArco({
        theme: '@arco-themes/react-arco-pro',
        modifyVars: {
          'arcoblue-6': setting.themeColor,
        },
      }),
      createSvgIconsPlugin({
        iconDirs: [resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]'
      }),

    ],
    rules: [

    ],
    // 配置路径别名
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
        '@service': resolve(__dirname, 'src/config/service'),
        '@ruom': resolve(__dirname, 'src/pages/ruom'),
        '@ruim': resolve(__dirname, 'src/pages/ruim')
      }
    },
    // 配置跨域
    server: {
      open: true,
      port: 20901,
      host: '127.0.0.1',
      proxy: {
        '/api': {
          target: 'http://127.0.0.1:3380',//'http://113.45.187.199:3380',//config.VITE_TARGET, // 会自动判断当前环境，对应上述三个文件中的target
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    }
  }
})
